import express from 'express';
import Sequelize from 'sequelize';
import { Advertise } from '../../modal/index'; // 数据库实体类
import { statusList, sequelizeStatus } from '../../common/status'; // 状态码对照
// import { checkPermission } from '../../utils/utils'; // 工具类

const router = express.Router();

router.post('/', async function (Request, Response, next) {
  // Advertise.Modal.sync();
  let param = Request.body
  Advertise.Modal.findAll({
    where: {
      type: param.type,
      expiredAt: {
        [Sequelize.Op.gt]: new Date()
      }
    },
    raw: true, // 返回标准json格式
    order: Sequelize.col('order'), // 排序
  }).then(res => {
    // if (res && res.length > 0) {
      Response.json({
        data: {
          list: res,
        },
        message: "success"
      });
    // } else {
    //   Response.status(300).send({ message: "抱歉，广告位查询失败" });
    // }
  }).catch(err => {
    console.log(err)
    Response.status(500).send({ message: sequelizeStatus[err.name] || statusList[500] || err.name });
  });
});



module.exports = router;